package com.xiaofei.view;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.example.net.R;
import com.xiaofei.model.TrafficStatModel;
import com.xiaofei.utils.NetUtils;

public class TrafficStatsFragment extends Fragment implements OnClickListener {

	Button mLinkBt;
	TextView tv;
	int uid;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub

		View layout = inflater.inflate(R.layout.fragment_urlconresult,
				container, false);
		PackageManager pm = getActivity().getPackageManager();
		try {
			ApplicationInfo ai = pm.getApplicationInfo("com.example.net",
					PackageManager.GET_ACTIVITIES);
			uid = ai.uid;
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mLinkBt = (Button) layout.findViewById(R.id.linkbt);
		tv = (TextView) layout.findViewById(R.id.tv);
		mLinkBt.setOnClickListener(this);

		return layout;

	}

	public void getInfo() {
		TrafficStatModel mModel = NetUtils.getTrafficStats(uid);
		// mInfoTv.setText(uid+"");
		tv.setText(mModel.toString());

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		getInfo();
	}

}